package com.bjb.vr.operation.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bjb.vr.common.ao.OptCusDevCtrlAo;
import com.bjb.vr.common.ao.OptCusDevDetailAo;
import com.bjb.vr.common.ao.ResDeviceAo;
import com.bjb.vr.common.dto.ResDevice;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.ResDeviceService;
import com.bjb.vr.common.vo.OptCusDevDetailVo;
import com.bjb.vr.common.vo.ResDeviceInstContVo;
import com.bjb.vr.common.vo.ResDeviceVo;
import com.bjb.vr.operation.service.ResDeviceCtrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0.0
 * @description:设备授权管理-设备列表,设备管理
 * @author: caihaibo
 * @createDate: 2022/8/5
 */
@RestController
@RequestMapping("/api/operation/v1")
public class DeviceController {


	@Autowired
	ResDeviceService resDeviceService;

	@Autowired
	ResDeviceCtrlService resDeviceCtrlService;

	/**
	 * 设备授权管理-选定租户下的设备列表分页记录
	 * @param resDeviceAo
	 * @return
	 */
	@PostMapping("/queryResDevicePage")
	public BaseResult<IPage<ResDevice>> queryResDevicePage(@RequestBody ResDeviceAo resDeviceAo) {
		IPage<ResDevice> voIPage = resDeviceService.queryResDevicePage(resDeviceAo);
		return CommonResult.Ok().setResult(voIPage);
	}

	/**
	 * 设备管理-选定租户下的设备列表分页记录
	 * @param resDeviceAo
	 * @return
	 */
	@PostMapping("/queryCtrlResDevicePage")
	public BaseResult<IPage<ResDeviceVo>> queryCtrlResDevicePage(@RequestBody ResDeviceAo resDeviceAo) {
		IPage<ResDeviceVo> voIPage = resDeviceService.queryCtrlResDevicePage(resDeviceAo);
		return CommonResult.Ok().setResult(voIPage);
	}

	/**
	 * 设备管理-设备操作
	 * @param optCusDevCtrlAo
	 * @return
	 */
	@PostMapping("/devBatchCtrl")
	public BaseResult devBatchCtrl(@RequestBody OptCusDevCtrlAo optCusDevCtrlAo) {
		resDeviceCtrlService.devBatchCtrl(optCusDevCtrlAo);
		return CommonResult.Ok();
	}

	/**
	 * 设备管理-单台设备操作
	 * @param optCusDevCtrlAo
	 * @return
	 */
	@PostMapping("/devSingleCtrl")
	public BaseResult devSingleCtrl(@RequestBody OptCusDevCtrlAo optCusDevCtrlAo) {
		resDeviceCtrlService.devSingleCtrl(optCusDevCtrlAo);
		return CommonResult.Ok();
	}

	/**
	 * 设备管理-查询单台设备信息
	 * @param optCusDevCtrlAo
	 * @return
	 */
	@PostMapping("/queryResDeviceDetail")
	public BaseResult<ResDeviceVo> queryResDeviceDetail(@RequestBody OptCusDevCtrlAo optCusDevCtrlAo){
		Assert.notNull(optCusDevCtrlAo.getUdid(),"设备udid不能为空!");
		Assert.notNull(optCusDevCtrlAo.getTenantId(),"租户id不能为空!");

		ResDeviceAo resDeviceAo = new ResDeviceAo();
		resDeviceAo.setUdid(optCusDevCtrlAo.getUdid());
		resDeviceAo.setTenantId(optCusDevCtrlAo.getTenantId());

		return resDeviceService.queryResDeviceDetail(resDeviceAo);

	}

	/**
	 * 设备管理-查询单台设备安装课程分页列表
	 * @param optCusDevCtrlAo
	 * @return
	 */
	@PostMapping("/queryResDeviceInstContentPage")
	public BaseResult<IPage<ResDeviceInstContVo>> queryResDeviceInstContentPage(@RequestBody OptCusDevCtrlAo optCusDevCtrlAo) {
		Assert.notNull(optCusDevCtrlAo.getUdid(),"设备udid不能为空!");
		Assert.notNull(optCusDevCtrlAo.getTenantId(),"租户id不能为空!");

		ResDeviceAo resDeviceAo = new ResDeviceAo();
		resDeviceAo.setUdid(optCusDevCtrlAo.getUdid());
		resDeviceAo.setTenantId(optCusDevCtrlAo.getTenantId());
		resDeviceAo.setCurrent(optCusDevCtrlAo.getCurrent());
		resDeviceAo.setSize(optCusDevCtrlAo.getSize());
		resDeviceAo.setInstCntName(optCusDevCtrlAo.getInstCntName());

		IPage<ResDeviceInstContVo> voIPage = resDeviceService.queryResDeviceInstContentPage(resDeviceAo);
		return CommonResult.Ok().setResult(voIPage);
	}

	/**
	 * 运营端统计页面-设备详情分页查询
	 */
	@PostMapping("/getDevicesByPage")
	public BaseResult<IPage<OptCusDevDetailVo>> getDevicesByPage(@RequestBody OptCusDevDetailAo optCusDevDetailAo) {
		IPage<OptCusDevDetailVo> voIPage = resDeviceService.getDevicesByPage(optCusDevDetailAo);
		return CommonResult.Ok().setResult(voIPage);
	}
}
